package com.gpnu7_412.yanzhi.controller.notice;

import com.gpnu7_412.yanzhi.entity.Notice;
import com.gpnu7_412.yanzhi.service.NoticeService;
import com.gpnu7_412.yanzhi.util.Result;
import com.gpnu7_412.yanzhi.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author HJJ
 */
@CrossOrigin
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    //获取用户通知
    @GetMapping("")
    public Result getNotice() {
        Map<String, Object> map = ThreadLocalUtil.get();
        List<Notice> noticeList = noticeService.getNoticeListByUserId((Integer) map.get("userId"));
        HashMap<String, Object> request = new HashMap<>();
        request.put("totalCount", noticeList.size());
        request.put("list", noticeList);
        return new Result(request);
    }

    //用户删除通知
    @DeleteMapping("/delete")
    public Result deleteByNoticeId(Integer noticeId) {
        noticeService.deleteNoticeById(noticeId);
        return new Result("通知删除成功");
    }
}
